
package com.lee.utils; 
 
import com.lee.source.HbaseSource; 
 
import java.io.IOException; 
 
public class CountsUtils { 
    private static String tableName = "marketing:counts";
    private static String activityFamily = "activity";
    private static String tagFamily = "tag";
    private static String qualifier = "join";
    private static String laplaceQualifier = "laplace_join";
    public static void initMap() throws IOException {
        HbaseSource.truncate(tableName);
    }
 
 
    public static void setActivityValueByKey(String key,String value) throws IOException {
 
        HbaseSource.put(key,tableName,activityFamily,qualifier,value);
    }
    public static void setTagValueByKey(String key,String value) throws IOException {
 
        HbaseSource.put(key,tableName,tagFamily,qualifier,value);
    }

    public static void setLaplaceActivityValueByKey(String key,long value) throws IOException {
        long laplaceValue = LaplaceUtils.laplaceMeth(value);
        String laplaceValueStr = String.valueOf(laplaceValue);
        HbaseSource.put(key,tableName,activityFamily,laplaceQualifier,laplaceValueStr);
    }
    public static void setLaplaceTagValueByKey(String key,long value) throws IOException {
        long laplaceValue = LaplaceUtils.laplaceMeth(value);
        String laplaceValueStr = String.valueOf(laplaceValue);
        HbaseSource.put(key,tableName,tagFamily,laplaceQualifier,laplaceValueStr);
    }
 
    public static long getActivityValueByKey(String key) throws IOException {
        String data = HbaseSource.get(key,tableName,activityFamily,qualifier);
        if(! "".equals(data)) {
            return Long.parseLong(data);
        } else {
            return 0;
        }
    }
 
    public static long getTagValueByKey(String key) throws IOException {
        String data = HbaseSource.get(key,tableName,tagFamily,qualifier);
        if(! "".equals(data)) {
            return Long.parseLong(data);
        } else {
            return 0;
        }
    }
 
 
 
 
 
 
 
 
 
} 
